<template lang="">
    <div>
        <el-dialog :before-close="cancel" center  title="会员修改" :visible.sync="isAdd">
  <el-form :model="memberForm"  :rules="rules"  label-width="100px"  ref="rules">
   <el-form-item label="手机号" prop="phone">
    <el-input v-model="memberForm.phone"></el-input>
  </el-form-item>
   <el-form-item label="昵称" prop="nickname">
    <el-input v-model="memberForm.nickname"></el-input>
  </el-form-item>
    <el-form-item label="密码" >
    <el-input v-model="memberForm.password"></el-input>
  </el-form-item>
          <el-form-item  label="状态">
   <el-switch
    v-model="memberForm.status"
    active-color="#13ce66"
    inactive-color="#ff4949"
    :active-value="1"
    :inactive-value="2">
  </el-switch>
</el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button  @click="cancel">取 消</el-button>
    <el-button type="primary"  @click="comfirm">确 定</el-button>
  </div>
</el-dialog>
    </div>
</template>
<script>
import { mapActions } from 'vuex';
import { memberInfo, memberEdit } from '../../request/api'
export default {
    props: ['isAdd'],
    data() {
        return {
            memberForm: {
                nickname: '',
                phone: '',
                password: '',
                status: 1
            },
            rules: {
                phone: [
                    { required: true, message: '请输入手机号', trigger: 'blur' },
                    { min: 3, max: 11, message: '长度在 3 到 11 个字符', trigger: 'blur' }
                ],
                nickname: [
                    { required: true, message: '请输入昵称', trigger: 'blur' },
                    { min: 3, max: 6, message: '长度在 3 到 6 个字符', trigger: 'blur' }
                ],
            },
            formLabelWidth: '120px'
        };
    },
    methods: {
        ...mapActions({
            getMember:"member/changeMemberListActions"
        }),
        // 重置事件
        reset() {
            this.memberForm = {
                nickname: '',
                phone: '',
                password: '',
                status: 1
            }
            // 清空表单验证
            this.$refs.rules.resetFields();
        },
        // 获取一条数据
        lookup(uid) {
            memberInfo({ uid }).then((res) => {
                console.log(res, '会员一天数据');
                if (res.code == 200) {
                    this.memberForm = res.list;
                    this.memberForm.uid = uid
                    // 注意  为空则不能做修改
                    this.memberForm.password = ''
                }
            })
        },
        cancel() {
            this.$emit('cancel', false)
        },
        comfirm() {
            this.$refs.rules.validate((val) => {
                if (val) {
                    this.$message.success('验证成功')
                    memberEdit(this.memberForm).then((res) => {
                        console.log(res, '编辑');
                        if (res.code == 200) {
                            this.$message.success(res.msg)
                            this.cancel()
                             this.getMember()
                        }else{
                            this.$message.error(res.msg)
                        }
                    })
                }else{
                    this.$message.error('验证失败')
                }
            })


        }
    },
}
</script>
<style lang="">
    
</style>